<link href="{SITE_URL}app/search/skins/default/style.css" rel="stylesheet">
<div class="s_index" style="margin-top: 50px;">
    <div class="s_menu">
        在虾米中搜索^ ^即将支持QQ哟~
        <a href="">
            &gt;&gt;切回普通发帖
        </a>
    </div>
    <div>
        <input class="s_input" name="kw" value="请输入歌名、专辑名、歌手" def="请输入歌名、专辑名、歌手" onfocus="if(this.value==$(this).attr('def')) this.value=''" onblur="if(this.value=='') this.value=$(this).attr('def')" onblur="if(this.value=='') this.value=$(this).attr('def')" />
        <input class="submit" style="font-size:14px;" type="button" value="搜 索" onclick="searchMusicList(1)" />
    </div>
    <div class="s_hotkey">
        热门搜索：
        <a href="javascript:;" onclick="hot_search(this)">trouble make</a>
        &nbsp;
        <a href="javascript:;" onclick="hot_search(this)">大哥</a>
        &nbsp;
        <a href="javascript:;" onclick="hot_search(this)">小城大事</a>
    </div>
    <div id="load">
    </div>
	<div class="clear"></div>
    <div id="page" style="text-align:center;">
    </div>
</div>
<div id="post_table" style="display:none">
    <table width="100%">
        <tbody>
		 <tr>
                <td>聚合:
				</td>
				<td>
				<input type="checkbox" name="juhe" value="1" checked="checked">聚合我发布的<strong style="color:#FF0000" id="juhe"></strong>专辑下的所有歌曲
				</td>
				
		</tr>		
            <tr>
                <td>
                    标签：
                </td>
                <td>
                    <input style="padding:3px 0;width:300px;color:#999999" name="tag" def="多个请以,分割"
                    onfocus="if(this.value==$(this).attr('def')) this.value=''" onblur="if(this.value=='') this.value=$(this).attr('def')"
                    />
                    <input type="checkbox" name="tag_ai" value="1" onclick="tag_ai_o(this)"
                    />
                    自动获取
                </td>
            </tr>
            <tr>
                <tr>
                    <td width="50">
                        歌曲
                    </td>
                    <td id="play1">
                    </td>
                </tr>
                <tr>
                    <td width="50">
                        标题*
                    </td>
                    <td>
                        <input style="padding:3px 0;width:600px;" type="text" name="title" />
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        内容*
                    </td>
                    <td>
                        <textarea style="width:600px;height:150px;font-size:14px;" id="editor_full"nname="content"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>
                        评论：
                    </td>
                    <td>
                        <input type="radio" checked="select" name="iscomment" value="0" />
                        允许
                        <input type="radio" name="iscomment" value="1" />
                        不允许
                    </td>
                </tr>
        </tbody>
    </table>
</div>
<script>
    var musicPage = 1;
    function hot_search(o) {
        $('input[name=\'kw\']').val($(o).html());
    }
    function play(id) {
        $('#play1').html('<embed src="http://st.xiami.com/res/player/widget/singlePlayer.swf?dataUrl=http://data.xiami.com/widget/xml-single/sid/' + id + '&autoplay=y" type="application/x-shockwave-flash" width="257" height="33" wmode="transparent" />&nbsp;&nbsp;<a href="javascript:;res()">重新选择</a>');
    }
    function searchMusicList(page) {
        var name = $('input[name=\'kw\']').val();
        musicPage = page;
        $('#load').html('搜索中。。。');
        $('#page').hide();
        var src1 = "http://kuang.xiami.com/app/nineteen/search/key/" + encodeURIComponent(name) + "/diandian/1/page/" + musicPage + "/callback/thinksaasxiami";
        var __musicList = '';
        var JSONP = document.createElement("script");
        JSONP.type = "text/javascript";
        JSONP.src = src1;
        document.getElementsByTagName("head")[0].appendChild(JSONP);
        JSONP.onload = JSONP.onreadystatechange = function() {
            if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
                JSONP.onload = JSONP.onreadystatechange = null;
            }
        }
    }
    function thinksaasxiami(jsonData) {
        __musicList = '';
        for (var i in jsonData.results) {
            __musicList += '<div class="sub-item"  style="text-align:left;"><span style="float:right;"><input type="checkbox" name="m" onclick="int(this)" id="' + jsonData.results[i].song_id + '" geshou="' + decodeURIComponent(jsonData.results[i].artist_name) + '" title="' + decodeURIComponent(jsonData.results[i].song_name) + '" logo="' + jsonData.results[i].album_logo + '" zhuanji="' + decodeURIComponent(jsonData.results[i].album_name) + '"/>就它啦！</span><div class="pic"><img src="' + jsonData.results[i].album_logo + '"/></div><div class="info">歌名：' + decodeURIComponent(jsonData.results[i].song_name) + '<p>歌手：' + decodeURIComponent(jsonData.results[i].artist_name) + '</p><p>专辑：' + decodeURIComponent(jsonData.results[i].album_name) + '</p></div></div>';
        }
        if (jsonData.total == 0) {
            __musicList = '<div><img height="48" width="48" src="{SITE_URL}app/group/thread/music/images/h202048.gif" align="absmiddle"/> 抱歉，没有找到关于 <font color="red">' + $('input[name=\'kw\']').val() + '</font> 的音乐。</div>';
            $('#load').html(__musicList);
            return false;
        }
        $('#load').html(__musicList);
        $('#page').show();
        if (jsonData.total > 8) {
            $('#page').html(pagerView(parseInt(jsonData.total), parseInt(musicPage)));
        }
    }
    function int(o) {
        $('input[name=\'m\']').attr('checked', '');
        b = $(o);
        b.attr('checked', 'checked');
        var html = '<input name="post[song_id]" value="' + b.attr('id') + '" type="hidden"><input name="post[logo]" type="hidden" value="' + b.attr('logo') + '"><input name="post[geming]" value="' + b.attr('title') + '" type="hidden"><input name="post[zhuanji]" value="' + b.attr('zhuanji') + '" type="hidden"><input name="post[geshou]" value="' + b.attr('geshou') + '" type="hidden">';
        $('#load').html($('#load').html() + html).hide();
        $('input[name=\'tag\']').val(b.attr('title') + ',' + b.attr('geshou'));
        play(b.attr('id'));
		$('#juhe').html('《'+b.attr('zhuanji')+'》');
        $('.s_index,.s_hotkey,.page').hide();
        $('.submit,#post_table').show();
    }
    function res() {
        $('.s_index,.s_hotkey,#load,.page').show();
        $('.submit,#post_table').hide();
    }
    function pagerView(dataCount, currentPage) {
        var __musicListPager = '<div class="page" id="music_pager"><a href="javascript:searchMusicList(' + (currentPage <= 1 ? 1 : currentPage - 1) + ');" onFocus="this.blur()" unselectable="on" title="上一页">上一页</a>';
        var __totalPage = dataCount / 8;
        __totalPage = __totalPage > parseInt(__totalPage) ? parseInt(__totalPage) + 1 : parseInt(__totalPage);
        var __forLength = currentPage > 10 ? (currentPage > 1000 ? 2 : 3) : 4;
        var __forStep = 2;
        var __forStart = (__totalPage > 4 && currentPage > __forStep) ? (currentPage < __totalPage - __forLength ? currentPage - __forStep: __totalPage - __forLength) : 1;
        var __forEnd = __forStart + __forLength < __totalPage + 1 ? __forStart + __forLength + 1 : __totalPage + 1;
        if (__totalPage > 4 && currentPage > __forStep + 1) __musicListPager += '<a href="javascript:searchMusicList(1)" onFocus="this.blur()" unselectable="on"  title="' + i + '" id="page_to_' + i + '" >1...</a>';
        for (var i = __forStart; i < __forEnd; i++) {
            if (currentPage == i) {
                __musicListPager += '<span class="current">' + i + '</span>';
            } else {
                __musicListPager += '<a href="javascript:searchMusicList(' + i + ')" onFocus="this.blur()" unselectable="on"  title="' + i + '" id="page_to_' + i + '" >' + i + '</a>';
            }
        }
        if (__forEnd < __totalPage) __musicListPager += '<a href="javascript:searchMusicList(' + __totalPage + ')" onFocus="this.blur()" unselectable="on" title="' + __totalPage + '" id="page_to_' + __totalPage + '">...' + __totalPage + '</a>';
        if (currentPage < __totalPage) {
            currentPage++;
			__musicListPager += '<a href="javascript:searchMusicList(' + currentPage + ')" onFocus="this.blur()" unselectable="on" title="下一页" id="page_to_' + currentPage + '">下一页</a>';
        }
        __musicListPager += '<a href="javascript:searchMusicList(' + __totalPage + ')" onFocus="this.blur()" unselectable="on" title="最后一页" id="page_to_' + __totalPage + '">最后一页</a></div>';
        return __musicListPager;
    }
</script>